﻿using System;
using System.Collections;
using System.Data;
using System.Web.UI.WebControls;
using BLL;
using Utils;
namespace UI.ModSalary
{
    public partial class EmpSetsNo : System.Web.UI.Page
    {
        EmpSetsBiz empSetsBiz = new EmpSetsBiz();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DefDicBiz defDicBiz = new DefDicBiz();
                defDicBiz.InitDropDownList("Wage_Sets", ddlSetsID, "1");

                DataTable dt = empSetsBiz.GetLists();
                int r = dt.Rows.Count;
               
                if (r > 0)
                { 
                    gvList.DataSource = dt;
                gvList.DataBind();
                    lbNum.Text = "合计："+r.ToString();
                    Panel1.Visible = true;
                }
            }
        }

        protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
        {
            for (int i = 0; i <= gvList.Rows.Count - 1; i++)
            {
                CheckBox cbox = (CheckBox)gvList.Rows[i].FindControl("CheckBox1");
                if (CheckBox2.Checked == true)
                {
                    cbox.Checked = true;
                }
                else
                {
                    cbox.Checked = false;
                }
            }

        }

        protected void btnSet_Click(object sender, EventArgs e)
        {
            string setsID = ddlSetsID.SelectedValue.ToString();

            if (setsID == "" || setsID == "0")
            {
                Utils.JSUtility.Alert(this, "请选择帐套");
                return;
            }


            ArrayList empCodeArray = new ArrayList();
           
            foreach (GridViewRow gvr in gvList.Rows)
            {
                CheckBox ch = (CheckBox)gvr.FindControl("CheckBox1");
                if (ch.Checked == true)
                {

                    string strTmp = this.gvList.DataKeys[gvr.DataItemIndex].Value.ToString();
                    empCodeArray.Add(strTmp);                   
                }
             
            }
            if (empSetsBiz.ConfigSets(empCodeArray, setsID))
            { JSUtility.Alert(this,"设置帐套成功"); }
            else
            { JSUtility.Alert(this, "设置帐套失败"); }
           


        }
    }
}